﻿Public Class LibraryMonitorRealtimeItem
  Implements IComparable(Of LibraryMonitorRealtimeItem)

  Private _action As ActionType = ActionType.Updated
  Private _oldFullPath As String = String.Empty
  Private _fullPath As String = String.Empty
  Private _name As String = String.Empty

  Public Enum ActionType
    None ' No Op
    Created
    Renamed
    Deleted
    Updated
    FullScan
  End Enum

  Public Property Action() As ActionType
    Get
      Return Me._action
    End Get
    Set(ByVal value As ActionType)
      Me._action = value
    End Set
  End Property

  Public Property OldFullPath() As String
    Get
      Return Me._oldFullPath
    End Get
    Set(ByVal value As String)
      Me._oldFullPath = value
    End Set
  End Property

  Public Property FullPath() As String
    Get
      Return Me._fullPath
    End Get
    Set(ByVal value As String)
      Me._fullPath = value
    End Set
  End Property

  Public Property Name() As String
    Get
      Return Me._name
    End Get
    Set(ByVal value As String)
      Me._name = value
    End Set
  End Property

  Public Function CompareTo(ByVal other As LibraryMonitorRealtimeItem) As Integer Implements System.IComparable(Of LibraryMonitorRealtimeItem).CompareTo
    Select Case Me.Action
      Case ActionType.None, ActionType.FullScan
        If other.Action = Me.Action Then
          Return 0
        End If
      Case ActionType.Created, ActionType.Deleted, ActionType.Updated
        Return String.Compare(Me.FullPath, other.FullPath, True)
      Case ActionType.Renamed
        Dim cmp As Integer = String.Compare(Me.OldFullPath, other.OldFullPath, True)
        If cmp = 0 Then
          Return String.Compare(Me.FullPath, other.FullPath, True)
        Else
          Return cmp
        End If
    End Select
    Return -1
  End Function

  Public Overrides Function Equals(ByVal obj As Object) As Boolean
    If obj.GetType Is GetType(LibraryMonitorRealtimeItem) Then
      Return (Me.CompareTo(CType(obj, LibraryMonitorRealtimeItem)) = 0)
    End If
    Return False
  End Function
End Class
